<template>
    <div clas>

        <div class="detail-view">
            <div class="detail-img">
                <img :src="goodsDetail.img">
            </div>
            <div class="detail-text-bac">
                <div class="text">
                    {{ goodsDetail.title }}
                </div>
                <div class="price-box">
                    <div class="price">${{ goodsDetail.price }}</div>
                    <div class="old-price" v-if="goodsDetail.originalPrice">${{ goodsDetail.originalPrice }}</div>
                </div>
            </div>
            <div class="describe-box">
                <div class="describe-title">Describe</div>
                <div class="describe-content" v-html="goodsDetail.introdaction"></div>
            </div>
            <div class="footer-box" @click="toShappingCart">
                <PublicButton myWidth="343px" myHeight="44px" content="Add to Cart"></PublicButton>
                <div class="line-box">
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import PublicButton from "../../components/button/PublicButton"
import { mapActions, mapGetters } from 'vuex'
export default {
    name: "GoodDetail",
    data() {
        return {
            id: 0,
            goodsDetail: []
        }
    },
    methods: {
        // toShappngCard() {
        //     this.$store.commit(
        //         "shopMuneOption/addShoppingCard", {
        //         id: this.goodsDetail.id,
        //         title: this.goodsDetail.title,
        //         num: 1,
        //         price: this.goodsDetail.price,
        //         originalPrice: this.goodsDetail.originalPrice,
        //         img: this.goodsDetail.img
        //     }
        //     )
        //     this.$router.push('/cart')
        // }
        ...mapActions({
            toShappingCart(dispatch) {
                dispatch("shopMuneOption/handlerShopingCart",
                    {
                        id: this.goodsDetail.id,
                        title: this.goodsDetail.title,
                        num: 1,
                        price: this.goodsDetail.price,
                        originalPrice: this.goodsDetail.originalPrice,
                        img: this.goodsDetail.img
                    })
            }
        })
    },
    computed: {
        ...mapGetters({
            goods: 'shopMuneOption/getGoodsById'
        }
        )
    },
    components: {
        PublicButton,
    },
    mounted() {
        this.id = this.$route.query.id
        this.goodsDetail = this.goods(this.id)
    }
}
</script>

<style scoped>
.detail-view {
    width: 100%;
    height: auto;
    overflow: scroll;
    margin-top: 46px;
    background-color: rgb(249, 249, 249);
}

.detail-view::-webkit-scrollbar {
    display: none;
}

.detail-img {
    /* top: 46px; */
    left: 0;
    width: 100%;
    height: 375px;
}

.detail-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-text-bac {
    width: 100%;
    height: auto;
    margin: 0 10px;
    padding-top: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(226, 226, 226, 0.7);
}

.text {
    display: -webkit-box;
    text-align: left;
    font-size: 18px;
    overflow: hidden;
    font-weight: 400;
    line-height: 24px;
    letter-spacing: 0px;
    font-family: Noto Sans;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.price-box {
    display: flex;
    width: 100%;
    height: 24px;
    padding-top: 12px;
    /* justify-items: center; */
    align-items: center;
}

.price {
    display: inline;
    font-weight: 400;
    font-size: 18px;
    line-height: 24px;
    letter-spacing: 0px;
    text-align: left;
    font-family: Noto Sans;
}

.old-price {
    display: inline;
    font-size: 12px;
    text-align: left;
    line-height: 17px;
    letter-spacing: 0px;
    /* font-family: Inter; */
    font-weight: 400px;
    padding-left: 12px;
    text-decoration: line-through;
    color: rgb(152, 153, 154);
}

.describe-box {
    width: 100%;
    /* min-height: 176.8px; */
    height: auto;
    margin: 0 10px;
    padding-top: 15px;
    padding-bottom: 100px;
    /* margin-bottom: 100px; */
}

.describe-title {
    top: 0%;
    left: 0%;
    height: 18px;
    width: 107.22px;
    font-size: 16px;
    text-align: left;
    font-weight: 400;
    line-height: 18px;
    letter-spacing: 0px;
    font-family: Noto Sans;
    padding-bottom: 11px;
}

.describe-content {
    width: 100%;
    height: auto;
    /* min-height: 176.8px; */
    font-size: 13px;
    text-align: left;
    font-weight: 400;
    line-height: 16px;
    letter-spacing: 0px;
    padding-bottom: 7.2px;
    font-family: Noto Sans;
    color: rgb(124, 124, 124);
    /* 自动换行 */
    word-wrap: break-word;
    /* 将每个关键字的首字母转为大写 */
    text-transform: capitalize;

}

.footer-box {
    display: flex;
    position: fixed;
    flex-wrap: wrap;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 66px;
    padding-top: 16px;
    box-sizing: border-box;
    justify-content: center;
    background-color: #fff;
    border-top: 1px solid rgba(226, 226, 226, 0.7);
}

.line-box {
    padding-top: 21px;
}
</style>